package com.data.dbdao;

import com.data.bean.Account;
import com.data.util.LoginMethodUtils;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Transactional
public class LogindbDao extends BaseDao {

    /**
     * @param accountType，手机，邮箱，用户名
     * @param parms
     * @return
     */
    public Account loginMethodDao(String accountType, Object... parms) {
        StringBuilder hql = new StringBuilder("from Account where  password=? and ");
        String sql = LoginMethodUtils.getHql(hql, accountType);
        List<Account> list = (List<Account>) super.findMassageDao(sql, parms);
        return list.isEmpty() ? null : list.get(0);
    }

    /**
     * 不需要密码的查找账号
     *
     * @param accountType
     * @param parms
     * @return
     */
    public Account findAccountDao(String accountType, Object... parms) {
        StringBuilder hql = new StringBuilder("from Account where ");
        String sql = LoginMethodUtils.getHql(hql, accountType);
        List<Account> list = (List<Account>) super.findMassageDao(sql, parms);
        return list.isEmpty() ? null : list.get(0);
    }

    /**
     * 测试
     *
     * @param bytes
     * @param id
     * @return
     */

    public boolean updateChangeImageTest(byte[] bytes, String id) {
        String hql = "update RegistMassage set numpicture=? where id=?";
        return super.updateOneMssageDao(hql, bytes, id);
    }
}
